package C052;

import java.util.Arrays;

/**
 * ClassName: C02
 * Package: C052
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/3/18 20:40
 * @Version 1.0
 * @Since 1.0
 */
public class C02 {
    public static void main(String[] args) {
        int[] arr = {73,74,75,71,69,72,76,73};
        System.out.println(Arrays.toString(dailyTemperatures(arr)));
    }

    static int MAXLEN = 100001;

    static int[] stack = new int[MAXLEN];
    static int n, r;
    public static int[] dailyTemperatures(int[] temperatures) {
        n = temperatures.length;
        r = 0;
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            while(r > 0 && temperatures[stack[r - 1]] < temperatures[i]) {
                ans[stack[--r]] = i - stack[r];
            }
            stack[r++] = i;
        }
        return ans;
    }
}
